package com.testmycat.zbf.chongshi;

import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author: LCG
 * @date: 2022-05-16 20:48:06
 * @description:
 **/
@Component
public class MyService {

    private SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Retryable(value = {MyException.class},maxAttempts = 4,backoff =@Backoff(delay = 2000,multiplier = 2),listeners = {"mySpringRetryListener"})
    public void test01(int  iii){

        if(iii==1){
            System.out.println("==========出错进行重试------"+simpleDateFormat.format(new Date()));
            throw new MyException(iii+"");
        }else{
            System.out.println("==========执行OK");
        }

    }


}
